home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
AOL File Library: 2,401 to 2,500
/
aol-file-protocol-4400-2401-to-2500.zip
/
AOLDLs
/
Telecom Utilities
/
TELNET_ V11.3 AnzioWin 16-Bit
/
ANZWD113.exe
/
RECV-PC.C
< prev
next >
Wrap
C/C++ Source or Header
|
1993-02-17
|
4KB
|
129 lines
/* RECV-PC.C from RASMUSSEN SOFTWARE INC.
Version 1.0 11-21-89
Version 1.1 07-23-90 : We weren't always getting the 'end' indicator.
Version 1.2 04-21-92 : Use TCSETAW instead of TCSETA
Improve error handling
Version 2.0 02-17-93 : Change terminating character, in order to work with
ANZIO 9.7 and above
Move line reconfiguration higher
If no PC file name is given, use UNIX file name
Use Hex 1C, 1D for ANZIO commands (will only work
with ANZIO 9.7 and above)
*/
#include <stdio.h>
#include <errno.h>
#include <fcntl.h>
#include <termio.h>
#define DC2 0X12
#define DC4 0X14
#define BEL 0X07
#define MAX 8000
#define DONE 4
#define BADWRITE "ERROR ON WRITE IN UNIX"
#define TRUE 1
#define COMMAND_START 0X1C
#define COMMAND_END 0X1D
char ch;
char bufr[MAX];
int i;
int result;
struct termio tt_save;
struct termio tt_work;
long bytecount;
long linecount;
char pcfilename[256];
void send_command(s)
char *s;
{
printf("%c%s%c\n", COMMAND_START, s, COMMAND_END);
}
main(argc, argv)
int argc;
char *argv[];
{
int outfile;
printf("recv-pc Version 2.0 Copyright 1993 Robert Rasmussen\n");
if (argc < 2) {
printf("Format is: recv-pc <unixfilename> [<pcfilename>]\n\n");
exit(1);
}
outfile = open(argv[1],O_WRONLY | O_CREAT | O_TRUNC, 0666);
if (outfile == -1) {
printf("Can not open %s\n",argv[1]);
exit(1);
}
if (argc >= 3)
strcpy(pcfilename, argv[2]);
else
strcpy(pcfilename, argv[1]);
send_command("CLOSEI");
sprintf(bufr, "OPENI/S %s",pcfilename);
send_command(bufr);
ch = getchar(); /*leading zero*/
ch = getchar();
if (ch != '0') {
printf("Can't open PC file named %s\n", pcfilename);
exit(1);
}
ch = getchar();
ioctl(0, TCGETA, &tt_save);
tt_work = tt_save;
tt_work.c_lflag &= ~ICANON; /* turn off icanon */
tt_work.c_iflag |= IXOFF; /* turn on XON/XOFF */
tt_work.c_cc[4] = 4; /* 1.01 */
tt_work.c_cc[5] = 2; /* 1.01 */
ioctl(0, TCSETAW, &tt_work);
sprintf(bufr, "TRANSMIT TRAILER %c", DONE);
send_command(bufr);
i = 0;
linecount = 0;
bytecount = 0;
while (TRUE) {
ch = getchar();
if (ch == DONE) {
putchar(BEL);
if (i != (result = write(outfile, bufr, i))) {
if (result == -1) {
if (errno == EBADF)
printf("EBADF");
else if (errno == ENOSPC)
printf("ENOSPC");
} else
printf(BADWRITE);
ioctl(0, TCSETAW, &tt_save);
send_command("transmit off");
exit(1);
}
close(outfile);
ioctl(0, TCSETAW, &tt_save);
printf("Lines: %d Bytes: %d\n", linecount, bytecount);
exit(0);
}
if (ch == '\n')
linecount++;
bytecount++;
bufr[i++] = ch;
if (i >= MAX) {
if (MAX != write(outfile, bufr, MAX)) {
printf(BADWRITE);
ioctl(0, TCSETAW, &tt_save);
send_command("transmit off");
exit(1);
}
i = 0;
}
}
}